package torres.ability;

import java.util.List;

import torres.entity.Entity;
import torres.entity.NPC;
import torres.entity.Sneak;
import torres.map.Location;
import torres.map.World;
import torres.utility.Statistics;

/**
 * @author Torres
 * NonActionAbility that pickpockets other Entities
 */
public class PickPocketAbility extends NonActionAbility {

	/**
	 * Creates a new PickPocketAbility with given name
	 * @param name Name of PickPocketAbility
	 */
	public PickPocketAbility(String name, int id, List<Cost> costs) {
		super(name, id, costs);
	}
	
	/**
	 * Calls PickPocketAbility on the given Entity
	 * @param stealer Entity that will be pickpocketing
	 * @see torres.ability.NonActionAbility#useAbility(torres.entity.Entity)
	 */
	public void useAbility(Entity stealer) {
		Location loc = Location.locationInDirection(stealer.getLocation(), stealer.getDirection());
		Entity poorSap = World.getInstance().getEntity(loc);
		int stolen = 0;
		Sneak s = (Sneak)stealer.getOccupation();
		int skill = s.getPickPocketSkill();
		if(Statistics.attempt(skill, poorSap.getAgility())) {
			int toSteal = Statistics.normalDist(skill);
			stolen = poorSap.steal(toSteal);
			stealer.incGold(stolen);
		}
		else {
			((NPC)poorSap).setHostile();
		}
	}
}
